package com.yqg.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yqg.manage.entity.CaseArchiveStage;
import com.yqg.manage.mapper.CaseArchiveStageMapper;
import com.yqg.manage.service.ICaseArchiveStageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * CaseArchiveStageServiceImpl 服务实现类
 * @author yu
 * @since 2023-11-28
 */
@Service
public class CaseArchiveStageServiceImpl extends ServiceImpl<CaseArchiveStageMapper, CaseArchiveStage> implements ICaseArchiveStageService {
    @Resource
    private CaseArchiveStageMapper caseArchiveStageMapper;

    @Override
    public List<Long> passStage(String caseNo) {
        List<Long> resultList=new ArrayList<>();
        QueryWrapper<CaseArchiveStage> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("case_no",caseNo);
        queryWrapper.eq("status",1);
        List<CaseArchiveStage> passStages = caseArchiveStageMapper.selectList(queryWrapper);
        for (CaseArchiveStage passStage : passStages) {
            resultList.add(passStage.getPstageId());
        }
        return resultList;
    }

    /**
     * 新增案件保存阶段，并赋初值为0
     */
    @Override
    public void saveStage(String caseNo) {
        long stage=0;
        for (int i = 0; i < 7; i++) {
            CaseArchiveStage caseArchiveStage=new CaseArchiveStage();
            caseArchiveStage.setCaseNo(caseNo);
            caseArchiveStage.setStatus("0");
            caseArchiveStage.setPstageId(stage+=1000);
            caseArchiveStageMapper.insert(caseArchiveStage);
        }
    }

}
